<?php
/**
 * Author: Hancock
 * Email: 84622365@qq.com
 * Date: 3/23/2016
 * Des: 测试控制器
 */
defined('INHkMvc') or exit('Access Invalid!');

class TestController extends Controller
{
    public function indexAct()
    {
        $img = Factory::register('image', 'class', DEFAULT_UPLOAD_IMAGE_PATH . 'product' . SEPARATE);
        $res = $img->thumb('lanhua.jpg', 500, 500);
        var_dump($res);
    }

    public function dbTestAct()
    {
        ini_set("display_errors", 1);
        $res = DB::fetchAssoc("select * from hk_product");
        LD($res);
    }

    public function cacheTest()
    {
        ini_set("display_errors", DEBUG);
        var_dump(Cache::read('test'));
    }

    public function tableAct()
    {
        $product = new common('product');
        $tables = array(
            'product p',
            'shopnc.good'
        );
        $fields = array(
//            'id',
//            'p.id',
        );
        $where = array();
        $where[] = array('p.id' => array('eq', 'p.id', 'AND', true));
        // $where[] = array( 'p.id'=>array('like','1','OR'));
        // $where[] = array( 'id'=>array('in','1,2,3'));
        // $where[] = array( 'id'=>array('between',array('10','20')));
        // $where[] = array( 'id'=>array('or',array(array('eq', 'image'),array('id','neq','image', 'and' ,true))));
        // $where[] = array( 'id'=>array('exp','`xapp`.`p`.`id`=`shopnc`.`product`.`name`'));

        $join = array(
            'shopnc.good' => array('left',
                array('id', 'product p', 'p.id'),
                array('pid', 'shopnc.product_image', 'product_image.id')),
            'shopnc.good' => array('left',
                array('id', 'product p', 'p.id'),
                array('pid', 'shopnc.product_image', 'product_image.id')),
        );

        print_rr($product->tables($tables)->join($join)->fields($fields)->where($where)->select());
        //print_rr( $product->tables($tables)->fields($fields)->where($where)->select() );
          //    $sql='SELECT vr.`mp_admin`.`uid` FROM `vr_crm`.`hk_sys_admin`, `vr`.`mp_admin` WHERE vr.`mp_admin`.`uid` = `vr_crm`.`hk_sys_admin`.`id`';
          // var_dump(DB::fetchAll($sql));
           $where[] = array('vr.admin.uid' =>1);
           var_dump(M('vr.admin')->field('uid')->select($where));
          //var_dump(M('crm.sys_admin_group')->getPermissionByAdminId(1));
         
        //$tables = ['vr.customer'];
        // $join = array(
        //     'crm.sys_admin' => array('left',
        //         array('admin_uid', 'vr.customer', 'vr.customer.admin_uid'))
        // );
        //  $where[] = array('crm.sys_admin.admin_uid' => array('eq', 'vr.customer.admin_uid', 'AND', true));
        // $fields=[
        //           'crm.sys_admin' .'.*',
        //           'vr.customer.name',
        //           'vr.customer.mobile'
        //        ];
        //  var_dump(M('crm.sys_admin')->table($tables)->field($fields)->select($where));
//        $params = array();
//        $params[]=array(
//            'main_field'=>'id',
//                'alias' => 'p',
//                'tname' => 'product_image',
//            'sub_table'=>array(
//                'fields' => array(
//                    'image,i',
//                    'name'
//                ),
//            ),
//            'sub_field'=>'product_id'
//        );
//        print_rr( $product->table($params) );


        // 旧联表方式
        $tables = ['business', 'shop'];
        $where = [
            'id' => intval(29),
            'shop.member_id' => intval(2858),
        ];
        $where[] = array('business_id' => array('eq', 'business.id', 'AND', true));
        $where[] = array('business.shop_id' => array('eq', 'shop.id', 'AND', true));
        var_dump(Models('Business_activity')->tables($tables)->fields('id')->selectOne($where));
        // 新联表方式
        $where = [
            'id' => intval(29),
            'shop.member_id' => intval(2858),
            ['business_id' => ['business.id']],
            ['business.shop_id' => ['shop.id']],
        ];
        var_dump(Models('Business_activity')->tables($tables)->fields('id')->selectOne($where));
        // 新联表方式
        $where = [
            'id' => intval(29),
            'shop.member_id' => intval(2858),
            'business_id' => ['business.id'],
            'business.shop_id' => ['shop.id'],
        ];
        var_dump(Models('Business_activity')->tables($tables)->fields('id')->selectOne($where));
    }
     public function testAct(){
        $path='D:\www/good.json';
        $data=file_get_contents($path);
        $data=objectToArray(json_decode($data));
        $good = $data['data']['pagelist'];
       echo getGoodsUrl('554593655971',40,'yxjh','fhCPniShKxq');
     }

    public function getAct(){
        var_dump(ajaxReturn(200, taobaoCurl('click', ['num_iid' => '45133708564', 'ad_zone_id' => '65656869'])));
    }
}
